package com.UnionPayCenter.account.service.impl;

import com.UnionPayCenter.account.entity.AccountType;
import com.UnionPayCenter.account.enums.AccountTypeEnum;
import com.UnionPayCenter.account.service.AccountTypeService;
import com.UnionPayCenter.mapper.AccountTypeMapper;
import com.UnionPayCenter.util.Asserts;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class AccountTypeServiceImpl implements AccountTypeService {

    @Autowired
    private AccountTypeMapper accountTypeMapper;

    @Override
    @Transactional
    public void createAccountType(Integer shopId) {
        Asserts.naturalNumber(shopId, "店铺Id");

        for (AccountTypeEnum accountTypeEnum : AccountTypeEnum.values()) {
            AccountType accountType = new AccountType();
            accountType.setAccountType(accountTypeEnum);
            accountType.setShopId(shopId);
            accountType.setAccountTypeName(accountTypeEnum.msg());
            accountType.setDescription(accountTypeEnum.msg());
            accountType.setPriorityLevel(accountTypeEnum.code());
            accountType.setRefund(0);
            accountType.setCreateTime(new Date());
            accountType.setUpdateTime(new Date());
            accountTypeMapper.insert(accountType);
        }
    }

    @Override
    public List<AccountType> getAccountTypeByShopId(Integer shopId) {
        Asserts.naturalNumber(shopId, "商户Id");
        return accountTypeMapper.selectByMerchantId(shopId);
    }

    @Override
    public AccountType getAccountTypeById(Long accountTypeId) {
        return accountTypeMapper.selectByPrimaryKey(accountTypeId);
    }
}
